var CreatedOKLodop7766=null;
var conf = {
	'full_name' : WG.fullname,
	'address' : WG.address,
	'telephone' : WG.telephone,
};

//====判断是否需要安装CLodop云打印服务器:====
function needCLodop(){
    try{
	var ua=navigator.userAgent;
	if (ua.match(/Windows\sPhone/i) !=null) return true;
	if (ua.match(/iPhone|iPod/i) != null) return true;
	if (ua.match(/Android/i) != null) return true;
	if (ua.match(/Edge\D?\d+/i) != null) return true;
	
	var verTrident=ua.match(/Trident\D?\d+/i);
	var verIE=ua.match(/MSIE\D?\d+/i);
	var verOPR=ua.match(/OPR\D?\d+/i);
	var verFF=ua.match(/Firefox\D?\d+/i);
	var x64=ua.match(/x64/i);
	if ((verTrident==null)&&(verIE==null)&&(x64!==null)) 
		return true; else
	if ( verFF !== null) {
		verFF = verFF[0].match(/\d+/);
		if ((verFF[0]>= 41)||(x64!==null)) return true;
	} else 
	if ( verOPR !== null) {
		verOPR = verOPR[0].match(/\d+/);
		if ( verOPR[0] >= 32 ) return true;
	} else 
	if ((verTrident==null)&&(verIE==null)) {
		var verChrome=ua.match(/Chrome\D?\d+/i);		
		if ( verChrome !== null ) {
			verChrome = verChrome[0].match(/\d+/);
			if (verChrome[0]>=41) return true;
		};
	};
        return false;
    } catch(err) {return true;};
};

//====页面引用CLodop云打印必须的JS文件：====
if (needCLodop()) {
	var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
	var oscript = document.createElement("script");
	oscript.src ="http://localhost:8000/CLodopfuncs.js?priority=1";
	head.insertBefore( oscript,head.firstChild );

	//引用双端口(8000和18000）避免其中某个被占用：
	oscript = document.createElement("script");
	oscript.src ="http://localhost:18000/CLodopfuncs.js?priority=0";
	head.insertBefore( oscript,head.firstChild );
};

//====获取LODOP对象的主过程：====
function getLodop(oOBJECT,oEMBED){
    var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='/static/lodop/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='/static/lodop/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
    var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='/static/lodop/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='/static/lodop/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
    var strHtmFireFox="<br><br><font color='#FF00FF'>（注意：如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它）</font>";
    var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常，仅因浏览器升级或重安装而出问题，需重新执行以上安装）</font>";
    var strCLodopInstall="<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='/static/lodop/CLodop_Setup_for_Win32NT.exe' target='_self'>执行安装</a>,安装后请刷新页面。</font>";
    var strCLodopUpdate="<br><font color='#FF00FF'>CLodop云打印服务需升级!点击这里<a href='/static/lodop/CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
    var LODOP;
    try{
        var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
        if (needCLodop()) {
            try{ LODOP=getCLodop();} catch(err) {};
	    if (!LODOP && document.readyState!=="complete") {alert("C-Lodop没准备好，请稍后再试！");return false; };
            if (!LODOP) {
		 if (isIE) document.write(strCLodopInstall); else
		 	 $('.widget-body,.print-warp').before(strCLodopInstall);
                 return;
            } else {

	         if (CLODOP.CVERSION<"3.0.4.3") { 
			if (isIE) document.write(strCLodopUpdate); else
			 $('.widget-body,.print-warp').append(strCLodopUpdate);
		 };
		 if (oEMBED && oEMBED.parentNode) oEMBED.parentNode.removeChild(oEMBED);
		 if (oOBJECT && oOBJECT.parentNode) oOBJECT.parentNode.removeChild(oOBJECT);	
	    };
        } else {
            var is64IE  = isIE && (navigator.userAgent.indexOf('x64')>=0);
            //=====如果页面有Lodop就直接使用，没有则新建:==========
            if (oOBJECT!=undefined || oEMBED!=undefined) {
                if (isIE) LODOP=oOBJECT; else  LODOP=oEMBED;
            } else if (CreatedOKLodop7766==null){
                LODOP=document.createElement("object");
                LODOP.setAttribute("width",0);
                LODOP.setAttribute("height",0);
                LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
                if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
                else LODOP.setAttribute("type","application/x-print-lodop");
                document.documentElement.appendChild(LODOP);
                CreatedOKLodop7766=LODOP;
             } else LODOP=CreatedOKLodop7766;
            //=====Lodop插件未安装时提示下载地址:==========
            if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
                 if (navigator.userAgent.indexOf('Chrome')>=0)
					 $('.widget-body,.print-warp').before(strHtmChrome);
                 if (navigator.userAgent.indexOf('Firefox')>=0)
				  	 $('.widget-body,.print-warp').before(strHtmFireFox);
                 if (is64IE) document.write(strHtm64_Install); else
                 if (isIE)   document.write(strHtmInstall);    else
					  $('.widget-body,.print-warp').before(strHtmInstall);
                 return LODOP;
            };
        };
        if (LODOP.VERSION<"6.2.2.2") {
            if (!needCLodop()){
            	if (is64IE) document.write(strHtm64_Update); else
            	if (isIE) document.write(strHtmUpdate); else
				 $('.widget-body,.print-warp').before(strHtmUpdate);
	    };
            return LODOP;
        };
        //===如下空白位置适合调用统一功能(如注册语句、语言选择等):===

        //===========================================================
        return LODOP;
    } catch(err) {alert("getLodop出错:"+err);};
};

var printType = new Object;
printType.defaults = 'Epson WF-C5290a'; //默认打印机A4
printType.retail = '中盈税之星 QS-312K';  //销售单打印
printType.product = 'Epson WF-C5290a';  //产品标签打印

/**
* 打印html
*/
function lodop_print_html(title,html,printer,width,height)
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.ADD_PRINT_HTM(0, 0,'100%','100%', html);
	LODOP.PREVIEW();
}

/**
* 预览
*/
function lodop_preview_html(title,html,printer,width,height)
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.ADD_PRINT_HTM(0, 0,'100%','100%', html);
	
	LODOP.PREVIEW();
}

/**
* 获取打印机名称
*/
function lodop_get_printer_name()
{
	LODOP = getLodop();
	var iPrinterCount=LODOP.GET_PRINTER_COUNT();
	var arrList = new Array();
	for(var i=0;i<iPrinterCount;i++)
	{
		arrList.push(LODOP.GET_PRINTER_NAME(i));
	};
	return arrList;
}

/**
* 按坐标打印
*/
function lodop_coordinate_print(title,coordinate,printer,width,height) 
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.PREVIEW();
}

/**
* 打印销售单-科视
*/
function createRetailPrinter(d) 
{
		var tables = '<div class="print_template">\
		<div class="caption">'+ conf.full_name +'</div>\
	<table class="notables topnotables">\
	  <tr><td  width="5%">配镜单号：</td><td><span id="ManualNumber"></span></td>\
	    <td nowrap="nowrap">配镜日期：</td>\
	    <td nowrap="nowrap"><span id="RCreatedAt"></span></td>\
	    <td nowrap="nowrap">取镜日期：</td>\
	    <td nowrap="nowrap"><span id="QjDate"></span></td>\
      </tr>\
	  <tr><td  width="5%">顾客姓名：</td><td><span id="Realname"></span></td><td nowrap="nowrap">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</td><td><span id="Sex"></span></td><td>出生年月：</td><td nowrap="nowrap"><span id="Birthday"></span></td></tr>\
	  <tr><td nowrap="nowrap">移动电话：</td><td nowrap="nowrap"><span id="Mobile"></span></td>\
	    <td  width="5%">联系地址：</td>\
	    <td colspan="3"><span id="Address" class="w100" style="width:95%;"></span></td>\
      </tr>\
	</table>\
    <table class="tables" style="margin-top:10px;" data-type="chufang">\
    <tr><td>眼别</td><td>球镜</td><td>柱镜</td><td>轴位</td><td>近瞳距(mm)</td><td>远瞳距(mm)</td><td>瞳高(mm)</td><td>裸眼</td><td>矫正</td><td>ADD</td><td>通道</td><td>棱镜</td><td>基底</td></tr>\
    <tr data-type="right"><td>右眼</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="pd_yuan"></td><td data-type="pd_yuan"></td><td data-type="mrp"></td><td data-type="nv"></td><td data-type="cv"></td><td data-type="add_info"></td><td data-type="pass"></td><td data-type="v"></td><td data-type="bc"></td></tr>\
    <tr data-type="left"><td>左眼</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="pd_yuan"></td><td data-type="pd_yuan"></td><td data-type="mrp"></td><td data-type="nv"></td><td data-type="cv"></td><td data-type="add_info"></td><td data-type="pass"></td><td data-type="v"></td><td data-type="bc"></td></tr>\
	</table>\
    <table class="tables" style="margin-top:10px;margin-bottom:10px;">\
      <tr><td colspan="6" style="text-align:center; font-size:15px;">商品信息</td></tr>\
      <tr><td></td><td>商品名称</td><td>数量</td><td>单位</td><td>零售价</td><td>小计</td></tr>\
      <tbody id="databody"></tbody>\
    </table>\
	<table class="notables" width="100%">\
	  <tr><td width="5%">付款方式：</td><td colspan="7"><span id="fukuanfs" class="w100"></span></td><td width="5%">总计价格：</td><td><span id="zhongjijiage"></span></td><td width="5%">调减金额：</td><td><span id="tiaojianje"></span></td></tr>\
	  <tr><td width="5%">验&nbsp;&nbsp;光&nbsp;&nbsp;师：</td><td width="5%"><span id="yanguangshi"></span></td><td>销&nbsp;&nbsp;售&nbsp;&nbsp;员：</td><td width="5%"><span id="xiaoshouyuan"></span></td><td>收&nbsp;&nbsp;银&nbsp;&nbsp;员：</td><td width="5%"><span id="shouyingyuan"></span></td><td>加&nbsp;&nbsp;工&nbsp;&nbsp;师：</td><td><span id="jiagongyuan"></span></td><td width="5%">小计价格：</td><td><span id="xiaojiejine"></span></td><td width="5%">实收金额：</td><td><span id="shishoujine"></span></td></tr>\
	  <tr><td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</td><td colspan="7"><span id="beizhu" class="w100"></span></td><td></td><td colspan="3"></td></tr>\
	  <tr><td>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</td><td colspan="7"><span  class="w100" id="dizhi"></span></td><td>电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话：</td><td colspan="3"><span class="w100" id="dianhua"></td></tr>\
	</table>\
	</div>';

		LODOP=getLodop();
		//LODOP.PRINT_INITA(0,0,"210.08mm","145.79mm","销售单打印");
    	LODOP.SET_PRINT_PAGESIZE(0,"210.08mm","145.79mm","A4");
    	LODOP.SET_PRINTER_INDEX(printType.retail);
    	LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);

    	var tabJquery = $(tables); //表格转成JQ对象

    	tabJquery.find('#theader').html('<b>'+ conf.full_name +'</b>');
		
    	tabJquery.find('#dizhi').html(conf.address );
    	tabJquery.find('#dianhua').html(conf.telephone);

		setHtml = function(d) {
			$.each(d, function(k,v){
				if(k == 'CreatedAt'&&d.BusinessId) {
                    tabJquery.find('#RCreatedAt').html(timetransDate(v));
				} else if(k == 'TotalMoney') {
                    tabJquery.find('#TotalMoney').html(v);
                    tabJquery.find('#TotalMoneyBig').html(smalltoBIG(v));
				}else {
					if(tabJquery.find('#'+k)) {
                        tabJquery.find('#'+k).html(v);
					}
				}
			});
		};
		//客户资料
		if(d.archives) {
			setHtml(d.archives);
		}
		//验光数据
		if(d.optometry) {
			if(d.optometry.chufang) {
				var box = tabJquery.find('[data-type="chufang"]');
				$.each(d.optometry.chufang, function (idx, value) {
					$.each(value, function (xx, val) {
						$.each(val, function (cc, vv) {
							box.find('[data-type="'+ xx +'"]').find('[data-type="'+ cc +'"]').html(vv);
						});
					});
				});
			}
		}
		//付款方式	
		if(d.retail.AlreadyMoney > 0) {
			fukuanfs = '';
			if(d.retail.AlipayMoney>0) {
				fukuanfs += '支付宝：'+toDecimal2(d.retail.AlipayMoney);
			}
			if(d.retail.WechatMoney>0) {
				fukuanfs += '微信：'+toDecimal2(d.retail.WechatMoney);
			}
			if(d.retail.CardMoney>0) {
				fukuanfs += '刷卡：'+toDecimal2(d.retail.CardMoney);
			}
			if(d.retail.CashMoney>0) {
				fukuanfs += '现金：'+toDecimal2(d.retail.CashMoney);
			}
			tabJquery.find('#fukuanfs').html(fukuanfs);
		} else {
			tabJquery.find('#fukuanfs').html('未付');
		}

		//总计
		tabJquery.find('#zhongjijiage').html(toDecimal2(d.retail.TotalMoney));
		//调减
		tabJquery.find('#tiaojianje').html(toDecimal2(d.retail.ChangesMoney));
		//小计金额
		tabJquery.find('#xiaojiejine').html(toDecimal2(d.retail.SumPayable));
		//实收金额
		tabJquery.find('#shishoujine').html(toDecimal2(d.retail.SumPayable));
		//销售员
		tabJquery.find('#xiaoshouyuan').html(d.retail.BusinessName);
		//验光师
		tabJquery.find('#yanguangshi').html(d.optometry ? d.optometry.Optometrist : '');
		//备注
		tabJquery.find('#beizhu').html(d.retail.Remarks);
		//配镜单号
		tabJquery.find('#ManualNumber').html(d.retail.ManualNumber);
		//配镜日期
		tabJquery.find('#RCreatedAt').html(timetransDate(d.retail.CreatedAt));

		
		//订单数据
		var RetailsDataLength = d.retail_data.length;
		var html = [];
		if(RetailsDataLength > 0) {
		   var rd = d.retail_data;
		   $.each(rd, function(idx, val){
			   html.push('<tr>');
			   html.push('<td>'+ (idx+1) +'</td>');
			   html.push('<td style="text-align:left;">'+ val.Products.Name +'</td>');
			   html.push('<td>'+ val.Amount +'</td>');
			   html.push('<td>'+ val.Products.Unit +'</td>');
			   html.push('<td style="text-align:right;">'+ toDecimal2(val.OriginalPrice) +'</td>');
			   html.push('<td style="text-align:right;">'+ toDecimal2(val.TotalPrice) +'</td>');
			   html.push('</tr>');
		   });
		}
		//产品补充
		cutRetailsDataLength = 5-RetailsDataLength;
		if(cutRetailsDataLength>=1) {
			for(i=1;i<=cutRetailsDataLength;i++) {
				html.push('<tr><td>&nbsp;</td><td></td><td></td><td></td><td></td><td></td></tr>');
			}
		}

		var style = "<style>\
		.print_template{}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse; width:100%;}\
		.caption{ font-size: 16px; padding-bottom: 10px; text-align:center;}\
		.tables tbody {}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 1.3; font-size: 10px;}\
		.tables tfoot td{ font-style: 11px; color: #666d70; padding-top: 10px;}\
		.tables tfoot #fmobile{ text-align: right;}\
		.notables{width: 100%; margin-top: 10px; color: #000; font-size: 10px;}\
		.notables td{font-size: 10px;line-height:20px; height:22px;white-space: nowrap; padding:0px; margin:0px;}\
		.notables .w100{ width:100%;}\
		.notables td span{ border-bottom:1px solid #000; width:60px; display:block;height:20px; text-align:left;overflow:hidden}\
		.topnotables{ margin-top: 0px;}\
		.topnotables td span{width:160px;}\
		</style>";
    	tabJquery.find('#databody').html(html.join(''));

		LODOP.ADD_PRINT_HTM(20,25,'200mm','140mm', style + '<body>' + tabJquery.html() + '</body>');
    	//LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",1);
		//LODOP.PRINT_SETUP();
		//LODOP.PRINTA(); //直接打印
		LODOP.PREVIEW();
}


/**
* 打印验光单-科视
*/
function setOptometryPrinterBoxText(obj, data) {
    var _this = $(obj);
    $.each(data, function (index, value) {
        _this.find('[data-type="'+ index +'"]').text(value);
    });
}
function createOptometryPrinter(d) {
	var tables = '<div class="print_template">\
		<div class="caption">'+ conf.full_name +'验光处方<br />Refrcating Prescription</div>\
	<table class="notables topnotables">\
	  <tr><td width="5%">验光单号（No.）：</td><td width="20%"><span id="DocumentNumber"></span></td>\
	    <td  width="5%" nowrap="nowrap">验光日期（Date）：</td>\
	    <td  width="20%"><span id="RCreatedAt"></span></td>\
	    <td width="5%" nowrap="nowrap">验光师（O.D.）：</td>\
	    <td><span id="Optometrist"></span></td>\
      </tr>\
	  <tr><td>姓名（Name）：</td><td><span id="Realname"></span></td><td nowrap="nowrap">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别（Sex）：</td><td><span id="Sex"></span></td><td>生日（Birthday）：</td><td nowrap="nowrap"><span id="Birthday"></span></td></tr>\
	</table>\
    <table class="tables" style="margin-top:10px;">\
		<tr><td colspan="2"></td><td>球镜<br>Sphere（D）</td><td>柱镜<br>Cylinder</td><td>轴位<br>Axis</td><td>棱镜<br>Prism</td><td>瞳距<br>P.D（mm）</td><td>裸眼<br>B.V.A </td><td>矫正<br>C.V.A</td></tr>\
	  	<tr data-type="far_right"><td rowspan="2">远用<br>Distance</td><td>OD</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td rowspan="2" data-type="total_pd_yuan"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr data-type="far_left"><td>OS</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr data-type="near_right"><td rowspan="2">近用<br>Near</td><td>OD</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td rowspan="2" data-type="total_pd_jin"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr  data-type="near_left"><td>OS</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr><td colspan="2">备注<br>Remarks</td><td colspan="7" id="Remarks" style="text-align: left;"></td></tr>\
    </table>\
	<table class="notables" width="100%">\
	  <tr><td width="5%">地址（Address）：</td><td colspan="7"><span  class="w100" id="dizhi"></span></td><td width="5%">电话（Telephone）：</td><td colspan="3"><span class="w100" id="dianhua"></td></tr>\
	</table>\
	</div>';
	/*
	<tr><td rowspan="2" valign="middle">其它（Other）</td><td valign="middle">&nbsp;</td><td>远用瞳距</td><td id="YuanyongTongju"></td><td>瞳高-R</td><td id="RTonggao"></td><td>ADD-R</td><td id="RAdd"></td><td></td></tr>\
		<tr><td valign="middle">&nbsp;</td><td>近用瞳距</td><td id="JinyongTongju"></td><td>瞳高-L</td><td id="LTonggao"></td><td>ADD-L</td><td id="LAdd"></td><td></td></tr>\
	*/
		LODOP=getLodop();
		//LODOP.PRINT_INITA(0,0,"210.08mm","145.79mm","销售单打印");
    	LODOP.SET_PRINT_PAGESIZE(0,"210.08mm","145.79mm","A4");
    	LODOP.SET_PRINTER_INDEX(printType.retail);
    	LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);

    	var tabJquery = $(tables); //表格转成JQ对象

    	tabJquery.find('#theader').html('<b>'+ conf.full_name +'</b>');
		
    	tabJquery.find('#dizhi').html(conf.address);
    	tabJquery.find('#dianhua').html(conf.telephone);

		setHtml = function(d) {
			
			$.each(d, function(k,v){
				if(k == 'CreatedAt') {
                    tabJquery.find('#RCreatedAt').html(timetransDate(v));
				}else if(k =="far" || k =="near") {
					if(v) {
						var data = v;
						if(k =="far") {
							setOptometryPrinterBoxText(tabJquery.find('[data-type="far_right"]'), data['right']);  //右眼
							tabJquery.find('[data-type="far_right"]').find('[data-type="total_pd_yuan"]').text(data['right'].total_pd_yuan);
							setOptometryPrinterBoxText(tabJquery.find('[data-type="far_left"]'), data['left']);  //左眼
						}
						if(k =="near") {
							setOptometryPrinterBoxText(tabJquery.find('[data-type="near_right"]'), data['right']);  //右眼
							setOptometryPrinterBoxText(tabJquery.find('[data-type="near_left"]'), data['left']);  //左眼
							tabJquery.find('[data-type="near_right"]').find('[data-type="total_pd_yuan"]').text(data['right'].total_pd_yuan);
						}
					}
				}else {
					if(tabJquery.find('#'+k)) {
                        tabJquery.find('#'+k).text(v);
					}
				}
			});
		};
		
		//档案数据
		if(d.Archives) {
			setHtml(d.Archives);
			setHtml(d);
		}
		//验光数据
		setHtml(d.chufang);

		var style = "<style>\
		.print_template{}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse; width:100%;}\
		.caption{ font-size: 18px; padding-bottom: 10px; text-align:center;}\
		.tables tbody {}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 22px; font-size: 14px;}\
		.tables tfoot td{ font-style: 11px; color: #666d70; padding-top: 10px;}\
		.tables tfoot #fmobile{ text-align: right;}\
		.notables{width: 100%; margin-top: 10px; color: #000; font-size: 10px;}\
		.notables td{font-size: 12px;line-height:23px; height:24px;white-space: nowrap; padding:0px; margin:0px;}\
		.notables .w100{ width:100%;}\
		.notables td span{ border-bottom:1px solid #000; width:60px; display:block;height:23px; text-align:left;overflow:hidden}\
		.topnotables{ margin-top: 0px;}\
		.topnotables td span{width:100%;}\
		</style>";
    	//tabJquery.find('#databody').html(html);
		LODOP.ADD_PRINT_HTM(20,25,'200mm','140mm', style + '<body>' + tabJquery.html() + '</body>');
		LODOP.PREVIEW();
}